﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CSmcCs;

namespace Status
{
	/// <summary>
	/// Summary description for Status.
	/// </summary>
	public class Status : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox txtDeviceName;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox cboTargetAxis;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.Button btnComOutPulse;
		private System.Windows.Forms.Button btnComEncPulse;
		private System.Windows.Forms.Label lblOutPulse;
		private System.Windows.Forms.Label lblCountPulse;
		private System.Windows.Forms.Label lblBank;
		private System.Windows.Forms.Label lblPulseSts;
		private System.Windows.Forms.Label lblMoveSts;
		private System.Windows.Forms.Label lblStopSts;
		private System.Windows.Forms.Label lblSd;
		private System.Windows.Forms.Label lblOrg;
		private System.Windows.Forms.Label lblMLim;
		private System.Windows.Forms.Label lblPLim;
		private System.Windows.Forms.Label lblAlm;
		private System.Windows.Forms.Button btnExit;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.Label lblComment;

		string		ErrorString;
		/////////////////////////////////////////////////
		// SMC access function
		/////////////////////////////////////////////////
		short		DevId=-1;
		int			dwRet;
		short		AxisNo;
		int			lOutPulse, lCountPulse;
		short		PulseSts, MoveSts, StopSts, LimitSts;
		private		System.Windows.Forms.Timer timer;

		CSmc		Smc	= new CSmc();


		public Status()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.btnExit = new System.Windows.Forms.Button();
			this.txtDeviceName = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.cboTargetAxis = new System.Windows.Forms.ComboBox();
			this.label2 = new System.Windows.Forms.Label();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.btnComEncPulse = new System.Windows.Forms.Button();
			this.btnComOutPulse = new System.Windows.Forms.Button();
			this.lblAlm = new System.Windows.Forms.Label();
			this.lblPLim = new System.Windows.Forms.Label();
			this.lblMLim = new System.Windows.Forms.Label();
			this.lblOrg = new System.Windows.Forms.Label();
			this.lblSd = new System.Windows.Forms.Label();
			this.lblStopSts = new System.Windows.Forms.Label();
			this.lblMoveSts = new System.Windows.Forms.Label();
			this.lblPulseSts = new System.Windows.Forms.Label();
			this.lblBank = new System.Windows.Forms.Label();
			this.lblCountPulse = new System.Windows.Forms.Label();
			this.label16 = new System.Windows.Forms.Label();
			this.label15 = new System.Windows.Forms.Label();
			this.label14 = new System.Windows.Forms.Label();
			this.label13 = new System.Windows.Forms.Label();
			this.label12 = new System.Windows.Forms.Label();
			this.label11 = new System.Windows.Forms.Label();
			this.label10 = new System.Windows.Forms.Label();
			this.lblOutPulse = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.lblComment = new System.Windows.Forms.Label();
			this.timer = new System.Windows.Forms.Timer(this.components);
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// btnExit
			// 
			this.btnExit.Location = new System.Drawing.Point(312, 424);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(96, 32);
			this.btnExit.TabIndex = 1;
			this.btnExit.Text = "EXIT";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// txtDeviceName
			// 
			this.txtDeviceName.AutoSize = false;
			this.txtDeviceName.Location = new System.Drawing.Point(104, 12);
			this.txtDeviceName.Name = "txtDeviceName";
			this.txtDeviceName.Size = new System.Drawing.Size(120, 22);
			this.txtDeviceName.TabIndex = 2;
			this.txtDeviceName.Text = "";
			this.txtDeviceName.TextChanged += new System.EventHandler(this.txtDeviceName_TextChanged);
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(8, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(79, 14);
			this.label1.TabIndex = 22;
			this.label1.Text = "Device Name";
			// 
			// cboTargetAxis
			// 
			this.cboTargetAxis.Location = new System.Drawing.Point(338, 12);
			this.cboTargetAxis.Name = "cboTargetAxis";
			this.cboTargetAxis.Size = new System.Drawing.Size(70, 23);
			this.cboTargetAxis.Sorted = true;
			this.cboTargetAxis.TabIndex = 3;
			this.cboTargetAxis.Text = "0";
			this.cboTargetAxis.SelectedIndexChanged += new System.EventHandler(this.cboTargetAxis_SelectedIndexChanged);
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(273, 16);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(47, 14);
			this.label2.TabIndex = 24;
			this.label2.Text = "Axis No";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.btnComEncPulse,
																					this.btnComOutPulse,
																					this.lblAlm,
																					this.lblPLim,
																					this.lblMLim,
																					this.lblOrg,
																					this.lblSd,
																					this.lblStopSts,
																					this.lblMoveSts,
																					this.lblPulseSts,
																					this.lblBank,
																					this.lblCountPulse,
																					this.label16,
																					this.label15,
																					this.label14,
																					this.label13,
																					this.label12,
																					this.label11,
																					this.label10,
																					this.lblOutPulse,
																					this.label9,
																					this.label8,
																					this.label7,
																					this.label6,
																					this.label5,
																					this.label4,
																					this.label3});
			this.groupBox1.Location = new System.Drawing.Point(8, 48);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(400, 264);
			this.groupBox1.TabIndex = 4;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "STATUS";
			// 
			// btnComEncPulse
			// 
			this.btnComEncPulse.Location = new System.Drawing.Point(296, 53);
			this.btnComEncPulse.Name = "btnComEncPulse";
			this.btnComEncPulse.Size = new System.Drawing.Size(96, 28);
			this.btnComEncPulse.TabIndex = 49;
			this.btnComEncPulse.Text = "Set Encpulse";
			this.btnComEncPulse.Click += new System.EventHandler(this.btnComEncPulse_Click);
			// 
			// btnComOutPulse
			// 
			this.btnComOutPulse.Location = new System.Drawing.Point(296, 22);
			this.btnComOutPulse.Name = "btnComOutPulse";
			this.btnComOutPulse.Size = new System.Drawing.Size(96, 28);
			this.btnComOutPulse.TabIndex = 48;
			this.btnComOutPulse.Text = "Set Outpulse";
			this.btnComOutPulse.Click += new System.EventHandler(this.btnComOutPulse_Click);
			// 
			// lblAlm
			// 
			this.lblAlm.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblAlm.Location = new System.Drawing.Point(317, 234);
			this.lblAlm.Name = "lblAlm";
			this.lblAlm.Size = new System.Drawing.Size(32, 18);
			this.lblAlm.TabIndex = 47;
			this.lblAlm.Text = "OFF";
			this.lblAlm.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// lblPLim
			// 
			this.lblPLim.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblPLim.Location = new System.Drawing.Point(267, 234);
			this.lblPLim.Name = "lblPLim";
			this.lblPLim.Size = new System.Drawing.Size(32, 18);
			this.lblPLim.TabIndex = 46;
			this.lblPLim.Text = "OFF";
			this.lblPLim.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// lblMLim
			// 
			this.lblMLim.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblMLim.Location = new System.Drawing.Point(218, 234);
			this.lblMLim.Name = "lblMLim";
			this.lblMLim.Size = new System.Drawing.Size(32, 18);
			this.lblMLim.TabIndex = 45;
			this.lblMLim.Text = "OFF";
			this.lblMLim.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// lblOrg
			// 
			this.lblOrg.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblOrg.Location = new System.Drawing.Point(168, 234);
			this.lblOrg.Name = "lblOrg";
			this.lblOrg.Size = new System.Drawing.Size(32, 18);
			this.lblOrg.TabIndex = 44;
			this.lblOrg.Text = "OFF";
			this.lblOrg.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// lblSd
			// 
			this.lblSd.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblSd.Location = new System.Drawing.Point(123, 234);
			this.lblSd.Name = "lblSd";
			this.lblSd.Size = new System.Drawing.Size(32, 18);
			this.lblSd.TabIndex = 43;
			this.lblSd.Text = "OFF";
			this.lblSd.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// lblStopSts
			// 
			this.lblStopSts.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblStopSts.Location = new System.Drawing.Point(128, 182);
			this.lblStopSts.Name = "lblStopSts";
			this.lblStopSts.Size = new System.Drawing.Size(220, 18);
			this.lblStopSts.TabIndex = 42;
			this.lblStopSts.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblMoveSts
			// 
			this.lblMoveSts.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblMoveSts.Location = new System.Drawing.Point(128, 151);
			this.lblMoveSts.Name = "lblMoveSts";
			this.lblMoveSts.Size = new System.Drawing.Size(220, 18);
			this.lblMoveSts.TabIndex = 41;
			this.lblMoveSts.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblPulseSts
			// 
			this.lblPulseSts.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblPulseSts.Location = new System.Drawing.Point(128, 120);
			this.lblPulseSts.Name = "lblPulseSts";
			this.lblPulseSts.Size = new System.Drawing.Size(220, 18);
			this.lblPulseSts.TabIndex = 40;
			this.lblPulseSts.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblBank
			// 
			this.lblBank.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblBank.Location = new System.Drawing.Point(128, 89);
			this.lblBank.Name = "lblBank";
			this.lblBank.Size = new System.Drawing.Size(96, 18);
			this.lblBank.TabIndex = 39;
			this.lblBank.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// lblCountPulse
			// 
			this.lblCountPulse.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblCountPulse.Location = new System.Drawing.Point(128, 58);
			this.lblCountPulse.Name = "lblCountPulse";
			this.lblCountPulse.Size = new System.Drawing.Size(96, 18);
			this.lblCountPulse.TabIndex = 38;
			this.lblCountPulse.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label16
			// 
			this.label16.AutoSize = true;
			this.label16.Location = new System.Drawing.Point(318, 215);
			this.label16.Name = "label16";
			this.label16.Size = new System.Drawing.Size(30, 14);
			this.label16.TabIndex = 37;
			this.label16.Text = "ALM";
			// 
			// label15
			// 
			this.label15.AutoSize = true;
			this.label15.Location = new System.Drawing.Point(267, 215);
			this.label15.Name = "label15";
			this.label15.Size = new System.Drawing.Size(32, 14);
			this.label15.TabIndex = 36;
			this.label15.Text = "+LIM";
			// 
			// label14
			// 
			this.label14.AutoSize = true;
			this.label14.Location = new System.Drawing.Point(219, 215);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(29, 14);
			this.label14.TabIndex = 35;
			this.label14.Text = "-LIM";
			// 
			// label13
			// 
			this.label13.AutoSize = true;
			this.label13.Location = new System.Drawing.Point(168, 215);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(33, 14);
			this.label13.TabIndex = 34;
			this.label13.Text = "ORG";
			// 
			// label12
			// 
			this.label12.AutoSize = true;
			this.label12.Location = new System.Drawing.Point(128, 215);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(22, 14);
			this.label12.TabIndex = 33;
			this.label12.Text = "SD";
			// 
			// label11
			// 
			this.label11.AutoSize = true;
			this.label11.Location = new System.Drawing.Point(232, 60);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(41, 14);
			this.label11.TabIndex = 32;
			this.label11.Text = "[pulse]";
			// 
			// label10
			// 
			this.label10.AutoSize = true;
			this.label10.Location = new System.Drawing.Point(232, 29);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(41, 14);
			this.label10.TabIndex = 31;
			this.label10.Text = "[pulse]";
			// 
			// lblOutPulse
			// 
			this.lblOutPulse.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblOutPulse.Location = new System.Drawing.Point(128, 27);
			this.lblOutPulse.Name = "lblOutPulse";
			this.lblOutPulse.Size = new System.Drawing.Size(96, 18);
			this.lblOutPulse.TabIndex = 30;
			this.lblOutPulse.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label9
			// 
			this.label9.AutoSize = true;
			this.label9.Location = new System.Drawing.Point(8, 215);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(69, 14);
			this.label9.TabIndex = 29;
			this.label9.Text = "Limit Status";
			// 
			// label8
			// 
			this.label8.AutoSize = true;
			this.label8.Location = new System.Drawing.Point(8, 184);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(68, 14);
			this.label8.TabIndex = 28;
			this.label8.Text = "Stop Status";
			// 
			// label7
			// 
			this.label7.AutoSize = true;
			this.label7.Location = new System.Drawing.Point(8, 153);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(73, 14);
			this.label7.TabIndex = 27;
			this.label7.Text = "Move Status";
			// 
			// label6
			// 
			this.label6.AutoSize = true;
			this.label6.Location = new System.Drawing.Point(8, 122);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(94, 14);
			this.label6.TabIndex = 26;
			this.label6.Text = "OutPulse Status";
			// 
			// label5
			// 
			this.label5.AutoSize = true;
			this.label5.Location = new System.Drawing.Point(8, 91);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(52, 14);
			this.label5.TabIndex = 25;
			this.label5.Text = "Bank No";
			// 
			// label4
			// 
			this.label4.AutoSize = true;
			this.label4.Location = new System.Drawing.Point(8, 60);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(87, 14);
			this.label4.TabIndex = 24;
			this.label4.Text = "Encoder Count";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Location = new System.Drawing.Point(8, 29);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(92, 14);
			this.label3.TabIndex = 23;
			this.label3.Text = "OutPulse Count";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.lblComment});
			this.groupBox2.Location = new System.Drawing.Point(8, 320);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(400, 96);
			this.groupBox2.TabIndex = 29;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "COMMENT";
			// 
			// lblComment
			// 
			this.lblComment.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblComment.Location = new System.Drawing.Point(8, 24);
			this.lblComment.Name = "lblComment";
			this.lblComment.Size = new System.Drawing.Size(384, 64);
			this.lblComment.TabIndex = 0;
			// 
			// timer
			// 
			this.timer.Tick += new System.EventHandler(this.timer_Tick);
			// 
			// Status
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(416, 462);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.groupBox2,
																		  this.groupBox1,
																		  this.btnExit,
																		  this.txtDeviceName,
																		  this.label1,
																		  this.cboTargetAxis,
																		  this.label2});
			this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "Status";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Status";
			this.Load += new System.EventHandler(this.Status_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Status());
		}

		private void Status_Load(object sender, System.EventArgs e)
		{
			AxisNo=1;
			// AxisNo ComboBox
			for( int i = 0; i < 8; i++ )
			{
				string	buf;
				buf = string.Format("{0:d}", i+1 );
				cboTargetAxis.Items.Add(buf);
			}
			cboTargetAxis.SelectedIndex = AxisNo - 1;

			txtDeviceName.Text = "SMC000";

			timer.Enabled = true;		// eventid=10 100msec 
		}

		private void DispComment(string func, string msg) 
		{
			lblComment.Text = string.Format("{0}: {1}", func, msg);
		}

		private void PollingTimer_Timer()
		{
			string	wStr;
			//---------------------------
			// Get OutPulse from Driver
			//---------------------------
			dwRet = Smc.WGetOutPulse(DevId, AxisNo, out lOutPulse);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetOutPulse", ErrorString);
				return;
			}
			wStr = string.Format("{0:d}", lOutPulse);
			lblOutPulse.Text = wStr;

			//---------------------------
			// Get CountPulse from Driver
			//---------------------------
			dwRet = Smc.WGetCountPulse(DevId, AxisNo, out lCountPulse);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetCountPulse", ErrorString);
				return;
			}
			wStr = string.Format("{0:d}", lCountPulse);
			lblCountPulse.Text = wStr;

			//---------------------------
			// Get BankNo from Driver
			//---------------------------
			short	wBankNo;
			dwRet = Smc.WGetBankNo(DevId, AxisNo, out wBankNo);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetBankNo", ErrorString);
				return;
			}
			wStr = string.Format("{0:d}", wBankNo);
			lblBank.Text = wStr;

			//-------------------------------
			// Get Pulse Status from Driver
			//-------------------------------
			dwRet = Smc.WGetPulseStatus(DevId, AxisNo, out PulseSts);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetPulseStatus", ErrorString);
				return;
			}
			switch( PulseSts )
			{
				case (short)CSmcConst.CSMC_PLS_STOP:
					wStr = "Pulse Stop";break;
				case (short)CSmcConst.CSMC_PLS_FLCONST:
					wStr = "Pulse FL Constant";break;
				case (short)CSmcConst.CSMC_PLS_FHCONST:
					wStr = "Pulse FH Constant";break;
				case (short)CSmcConst.CSMC_PLS_READY:
					wStr = "Pulse Ready";break;
				case (short)CSmcConst.CSMC_PLS_ERCW:
					wStr = "Pulse ERC Timer";break;
				case (short)CSmcConst.CSMC_PLS_DTMW:
					wStr = "Pulse Dir Timer";break;
				case (short)CSmcConst.CSMC_PLS_ACCEL:
					wStr = "Pulse Accel";break;
				case (short)CSmcConst.CSMC_PLS_DECEL:
					wStr = "Pulse Decel";break;
				case (short)CSmcConst.CSMC_PLS_INPW:
					wStr = "Pulse INP Wait";break;
				case (short)CSmcConst.CSMC_PLS_PAPBW:
					wStr = "Pulser Input Wait";break;
				default:
					wStr = "Unknown Status";break;
			}
			lblPulseSts.Text = wStr;

			//-------------------------------
			// Get Move Status from Driver
			//-------------------------------
			dwRet = Smc.WGetMoveStatus(DevId, AxisNo, out MoveSts);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetMoveStatus", ErrorString);
				return;
			}
			switch( MoveSts )
			{
				case (short)CSmcConst.CSMC_STOP:
					wStr = "Stop Motion";break;
				case (short)CSmcConst.CSMC_PTP:
					wStr = "PTP Motion";break;
				case (short)CSmcConst.CSMC_JOG:
					wStr = "JOG Motion";break;
				case (short)CSmcConst.CSMC_ORG:
					wStr = "ORG Motion";break;
				case (short)CSmcConst.CSMC_SINGLE:
					wStr = "Single (Bank) Motion";break;
				case (short)CSmcConst.CSMC_LOOP:
					wStr = "Loop (Bank) Motion";break;
				case (short)CSmcConst.CSMC_ZMOVE:
					wStr = "Z-phase count Motion";break;
				case (short)CSmcConst.CSMC_PLSER:
					wStr = "Pulser Motion";break;
				default:
					wStr = "Unknown Status";break;
			}
			lblMoveSts.Text = wStr;

			//-------------------------------
			// Get Stop Status from Driver
			//-------------------------------
			dwRet = Smc.WGetStopStatus(DevId, AxisNo, out StopSts);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetStopStatus", ErrorString);
				return;
			}
			switch( StopSts )
			{
				case (short)CSmcConst.CSMC_MOVE:
					wStr = "Moving";break;
				case (short)CSmcConst.CSMC_STOP_COMMAND:
					wStr = "Stop Command";break;
				case (short)CSmcConst.CSMC_SD_COMMAND:
					wStr = "Slowdown Stop Command";break;
				case (short)CSmcConst.CSMC_STOP_OTHER:
					wStr = "Stop by other axis";break;
				case (short)CSmcConst.CSMC_STOP_ALARM:
					wStr = "Stop by alarm";break;
				case (short)CSmcConst.CSMC_STOP_PLIM:
					wStr = "Stop by +LIM";break;
				case (short)CSmcConst.CSMC_STOP_MLIM:
					wStr = "Stop by -LIM";break;
				case (short)CSmcConst.CSMC_STOP_SD:
					wStr = "Stop by SD";break;
				case (short)CSmcConst.CSMC_ERROR_ORG:
					wStr = "Stop by ORG ERROR";break;
				case (short)CSmcConst.CSMC_ERROR_PULSER:
					wStr = "Stop by PULSER ERROR";break;
				case (short)CSmcConst.CSMC_STOP_NORMAL:
					wStr = "Normal Stop";break;
				default:
					wStr = "Unknown Status";break;
			}
			lblStopSts.Text = wStr;
			//-------------------------------
			// Get Limit Status from Driver
			//-------------------------------
			dwRet = Smc.WGetLimitStatus(DevId, AxisNo, out LimitSts);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetLimitStatus", ErrorString);
				return;
			}
			if( (LimitSts & (short)CSmcConst.CSMC_SD) == (int)CSmcConst.CSMC_SD )
				lblSd.Text = "ON";
			else
				lblSd.Text = "OFF";

			if( (LimitSts & (short)CSmcConst.CSMC_ORGLIM) == (int)CSmcConst.CSMC_ORGLIM )
				lblOrg.Text = "ON";
			else
				lblOrg.Text = "OFF";

			if( (LimitSts & (short)CSmcConst.CSMC_MLIM) == (int)CSmcConst.CSMC_MLIM )
				lblMLim.Text = "ON";
			else
				lblMLim.Text = "OFF";

			if( (LimitSts & (short)CSmcConst.CSMC_PLIM) == (int)CSmcConst.CSMC_PLIM )
				lblPLim.Text = "ON";
			else
				lblPLim.Text = "OFF";

			if( (LimitSts & (short)CSmcConst.CSMC_ALM) == (int)CSmcConst.CSMC_ALM )
				lblAlm.Text = "ON";
			else
				lblAlm.Text = "OFF";
		}

		private void btnComOutPulse_Click(object sender, System.EventArgs e)
		{
			//---------------------------
			// Set OutPulse for Driver
			//---------------------------
			dwRet = Smc.WSetOutPulse(DevId, AxisNo, 0);
			Smc.WGetErrorString(dwRet, out ErrorString);
			DispComment("SmcWSetOutPulse", ErrorString);
		}

		private void btnComEncPulse_Click(object sender, System.EventArgs e)
		{
			//---------------------------
			// Set CountPulse for Driver
			//---------------------------
			dwRet = Smc.WSetCountPulse(DevId, AxisNo, 0);
			Smc.WGetErrorString(dwRet, out ErrorString);
			DispComment("SmcWSetOutPulse", ErrorString);
		}

		private void timer_Tick(object sender, System.EventArgs e)
		{
			PollingTimer_Timer();
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			timer.Enabled = false;
			this.Close();
		}

		private void txtDeviceName_TextChanged(object sender, System.EventArgs e)
		{
			string	wStr="OK";
			string	DeviceName;

			if( DevId != -1 )
			{
				Smc.WExit(DevId);
			}
			DeviceName = txtDeviceName.Text;
			dwRet = Smc.WInit(DeviceName, out DevId);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWInit", ErrorString);
				DevId = -1;
				return;
			}
			lblComment.Text = wStr;
		}

		private void cboTargetAxis_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string	wStr="OK";
			short	InitParam;

			AxisNo = (short)(cboTargetAxis.SelectedIndex+1);
			// InitParam check
			dwRet = Smc.WGetInitParam(DevId , AxisNo , out InitParam);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetInitParam", ErrorString);
				return ;
			}
			if( InitParam == 0 )
			{ // SmcWSetInitParam
				dwRet = Smc.WSetInitParam(DevId , AxisNo);
			}
			lblComment.Text = wStr;
		}
	}
}
